package com.yc.exam.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.exam.entity.Topic;
import com.yc.exam.service.ITopicService;
import com.yc.exam.vo.TopicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 前端控制器
 *
 * @author exam
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/exam/topic")
public class TopicController {
  @Autowired private ITopicService topicService;

  /** 分页查询 */
  @GetMapping("/page")
  public Page<TopicVo> getPage(Page<Topic> examPage, TopicVo topic) {
    return topicService.loadVoPage(examPage,topic);
  }

  /** 保存或者更新题目数据 */
  @PostMapping
  public boolean saveOrUpdate(@RequestBody Topic topic) {
    return topicService.saveOrUpdate(topic);
  }

  /** 按照id 列表删除 */
  @DeleteMapping
  public boolean deleteByIds(@RequestBody Long[] ids) {
    return topicService.removeBatchByIds(Arrays.asList(ids));
  }

  @GetMapping("exam")
  public List<Topic> getTopicListByExamId(Long examId) {
    return topicService.getTopicListByExamId(examId);
  }
}
